**************************************
*Difference in Age (5th Percentile=1) 
**************************************

use "House_AgreementScoreData.dta"
gen BirthDistanceMiles=BirthDistance/1609.34
gen RepDistanceMiles=RepDistance/1609.34

gen BirthRegionAge=BirthRegion*Age
gen BirthDistanceAge=BirthDistanceMiles*Age

fracreg logit Agree BirthRegion BirthDistanceMiles Age BirthRegionAge BirthDistanceAge RepRegion RepDistanceMiles Party Gender Race DPres ChamSeniority i.congress, vce(robust)

drawnorm B1-B22, n(10000) means(e(b)) cov(e(V)) clear

*Enter values of variables
*duplicates drop congress icpsr, force [for everything but vote level variables]

forvalues i=0(10)2900 {
scalar BirthDistance=`i'
scalar BirthRegion=0
scalar Age=1
scalar BirthRegionAge=BirthRegion*Age 
scalar BirthDistanceAge=BirthDistance*Age 
scalar RepRegion=1
scalar RepDistance=1151.122
scalar Party=0  
scalar Gender=0 
scalar Race=0
scalar DPres=17.38107
scalar ChamSeniority=4.62341
scalar Cong107=.1103
scalar Cong108=.1088
scalar Cong109=.1093
scalar Cong110=.1133
scalar Cong111=.1118
scalar Cong112=.1118
scalar Cong113=.1113
scalar Cong114=.1098
scalar Cong115=.1133
scalar Constant=1

local counter=`i'
generate Sim`i'=B1*BirthRegion + B2*BirthDistance + B3*Age + B4*BirthRegionAge + B5*BirthDistanceAge + B6*RepRegion + B7*RepDistance + B8*Party + B9*Gender + B10*Race + B11*DPres + B12*ChamSeniority + B13*Cong107 + B14*Cong108 + B15*Cong109 + B16*Cong110 + B17*Cong111 + B18*Cong112 + B19*Cong113 + B20*Cong114 + B21*Cong115 + B22*Constant
generate Pred`i'=1/(1+exp(-(Sim`i')))
drop Sim`i'
}

*The _GCLSORT module is required to execute the clsort command
foreach var of varlist Pred0-Pred2900{
egen `var'a=clsort(`var')
}

*save "Age5th_ContOnly_Values.dta"

drop B1-Pred2900
gen scale=_n
*Keep the 8.25th and 91.75th percentiles
keep if scale==825 | scale==9175
xpose, clear
rename v1 LowBound
rename v2 UpBound
drop in 292
gen Miles=(_n-1)*10

move Miles LowBound
sort Miles

save "Age5th_ContOnly_Predictions.dta"

clear


**************************************
*Difference in Age (Median=10) 
**************************************

use "House_AgreementScoreData.dta"
gen BirthDistanceMiles=BirthDistance/1609.34
gen RepDistanceMiles=RepDistance/1609.34

gen BirthRegionAge=BirthRegion*Age
gen BirthDistanceAge=BirthDistanceMiles*Age

fracreg logit Agree BirthRegion BirthDistanceMiles Age BirthRegionAge BirthDistanceAge RepRegion RepDistanceMiles Party Gender Race DPres ChamSeniority i.congress, vce(robust)

drawnorm B1-B22, n(10000) means(e(b)) cov(e(V)) clear

*Enter values of variables
*duplicates drop congress icpsr, force [for everything but vote level variables]

forvalues i=0(10)2900 {
scalar BirthDistance=`i'
scalar BirthRegion=0
scalar Age=10
scalar BirthRegionAge=BirthRegion*Age 
scalar BirthDistanceAge=BirthDistance*Age 
scalar RepRegion=1
scalar RepDistance=1151.122
scalar Party=0  
scalar Gender=0 
scalar Race=0
scalar DPres=17.38107
scalar ChamSeniority=4.62341
scalar Cong107=.1103
scalar Cong108=.1088
scalar Cong109=.1093
scalar Cong110=.1133
scalar Cong111=.1118
scalar Cong112=.1118
scalar Cong113=.1113
scalar Cong114=.1098
scalar Cong115=.1133
scalar Constant=1

local counter=`i'
generate Sim`i'=B1*BirthRegion + B2*BirthDistance + B3*Age + B4*BirthRegionAge + B5*BirthDistanceAge + B6*RepRegion + B7*RepDistance + B8*Party + B9*Gender + B10*Race + B11*DPres + B12*ChamSeniority + B13*Cong107 + B14*Cong108 + B15*Cong109 + B16*Cong110 + B17*Cong111 + B18*Cong112 + B19*Cong113 + B20*Cong114 + B21*Cong115 + B22*Constant
generate Pred`i'=1/(1+exp(-(Sim`i')))
drop Sim`i'
}

*The _GCLSORT module is required to execute the clsort command
foreach var of varlist Pred0-Pred2900{
egen `var'a=clsort(`var')
}

*save "AgeMedian_ContOnly_Values.dta"

drop B1-Pred2900
gen scale=_n
*Keep the 8.25th and 91.75th percentiles
keep if scale==825 | scale==9175
xpose, clear
rename v1 LowBound
rename v2 UpBound
drop in 292
gen Miles=(_n-1)*10

move Miles LowBound
sort Miles

save "AgeMedian_ContOnly_Predictions.dta"

clear


****************************************
*Difference in Age (95th Percentile=28) 
****************************************

use "House_AgreementScoreData.dta"
gen BirthDistanceMiles=BirthDistance/1609.34
gen RepDistanceMiles=RepDistance/1609.34

gen BirthRegionAge=BirthRegion*Age
gen BirthDistanceAge=BirthDistanceMiles*Age

fracreg logit Agree BirthRegion BirthDistanceMiles Age BirthRegionAge BirthDistanceAge RepRegion RepDistanceMiles Party Gender Race DPres ChamSeniority i.congress, vce(robust)

drawnorm B1-B22, n(10000) means(e(b)) cov(e(V)) clear

*Enter values of variables
*duplicates drop congress icpsr, force [for everything but vote level variables]

forvalues i=0(10)2900 {
scalar BirthDistance=`i'
scalar BirthRegion=0
scalar Age=28
scalar BirthRegionAge=BirthRegion*Age 
scalar BirthDistanceAge=BirthDistance*Age 
scalar RepRegion=1
scalar RepDistance=1151.122
scalar Party=0  
scalar Gender=0 
scalar Race=0
scalar DPres=17.38107
scalar ChamSeniority=4.62341
scalar Cong107=.1103
scalar Cong108=.1088
scalar Cong109=.1093
scalar Cong110=.1133
scalar Cong111=.1118
scalar Cong112=.1118
scalar Cong113=.1113
scalar Cong114=.1098
scalar Cong115=.1133
scalar Constant=1

local counter=`i'
generate Sim`i'=B1*BirthRegion + B2*BirthDistance + B3*Age + B4*BirthRegionAge + B5*BirthDistanceAge + B6*RepRegion + B7*RepDistance + B8*Party + B9*Gender + B10*Race + B11*DPres + B12*ChamSeniority + B13*Cong107 + B14*Cong108 + B15*Cong109 + B16*Cong110 + B17*Cong111 + B18*Cong112 + B19*Cong113 + B20*Cong114 + B21*Cong115 + B22*Constant
generate Pred`i'=1/(1+exp(-(Sim`i')))
drop Sim`i'
}

*The _GCLSORT module is required to execute the clsort command
foreach var of varlist Pred0-Pred2900{
egen `var'a=clsort(`var')
}

*save "Age95th_ContOnly_Values.dta"

drop B1-Pred2900
gen scale=_n
*Keep the 8.25th and 91.75th percentiles
keep if scale==825 | scale==9175
xpose, clear
rename v1 LowBound
rename v2 UpBound
drop in 292
gen Miles=(_n-1)*10

move Miles LowBound
sort Miles

save "Age95th_ContOnly_Predictions.dta"

clear
